package com.janko.redislock.redisLock.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @ Description   :  类文件说明
 * @ Author        :  nieyankang
 * @ Version       :  1.0
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Value(value = "${swagger.enabled}")
    boolean enabled;

    @Bean("redisBase")
    public Docket ApiBase() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("redis常见场景")
                .apiInfo(apiInfo())
                .pathMapping("/")
                .enable(enabled)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.janko.redislock.redisLock.controller.scenes"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean("redisScenes")
    public Docket ApiScenes() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("redis基础操作")
                .apiInfo(apiInfo())
                .pathMapping("/")
                .enable(enabled)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.janko.redislock.redisLock.controller.base"))
                .paths(PathSelectors.any())
                .build();
    }

    public ApiInfo apiInfo(){
        return  new ApiInfoBuilder()
                .title("redis相关开发 API")
                .description("这是swagger的接口文档内容描述")
                .termsOfServiceUrl("http://www.xiangmu.com")
                .version("2.9.2")
                .build();
    }
}
